import axios from "axios";
import ElementUI from "element-ui";
import qs from "qs";

import Vue from "vue";
import VueAxios from "vue-axios";

import App from "./App.vue";
import router from "./router";
import "element-ui/lib/theme-chalk/index.css"; //样式要单独导入

Vue.use(VueAxios, axios);
Vue.use(qs);
Vue.use(ElementUI);
Vue.prototype.$axios = axios;
Vue.prototype.qs = qs;
Vue.config.productionTip = false;
//设置浏览器标题

Vue.directive("title", {
  inserted: function(el) {
    document.title = el.dataset.title;
  },
});

//请求拦截
axios.defaults.timeout = 30000;
axios.defaults.withCredentials = true;
axios.interceptors.request.use(
  config => {
    console.log(config);
    if (localStorage.getItem("token") || "") {
      config.headers["token"] = localStorage.getItem("token");
      // config.headers['app-key'] = "5ab089ca77014874868482ebb85b424b"
    }

    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

axios.interceptors.response.use(
  response => {
    return response;
  },
  error => {
    return Promise.reject(error);
  }
);

new Vue({
  router,
  render: h => h(App),
}).$mount("#app");
// 设置浏览器标题
